package io.github.javpower.knowledgerag.core;


import io.github.javpower.vectorexclient.res.DbData;
import io.github.javpower.vectorexclient.res.VectorSearchResult;

import java.util.List;
import java.util.Map;

public class ContextBuilder {
    public static String buildContext(List<VectorSearchResult> results) {

        // 构建上下文
        StringBuilder context = new StringBuilder();
        for (VectorSearchResult result : results) {
            if (result.getScore()<=0.9f) {
                DbData data = result.getData();
                Map<String, Object> metadata = data.getMetadata();
                Object text = metadata.get("text");
                context.append(text.toString().replaceAll("\n","").replaceAll("\t","")).append(" ");
            }
        }
        return context.toString().trim();
    }
}